package com.bwie.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.bwie.mapper.CollegeMapper;
import com.bwie.mapper.SchoolMapper;
import com.bwie.pojo.TbCollege;
import com.bwie.pojo.TbSchool;
import com.bwie.service.SchoolService;
import com.bwie.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @program: day0617mounth
 * @ClassName SchoolServiceImpl
 * @description:
 * @author: 段阳
 * @create: 2024-06-17 10:00
 **/
@Service
@Transactional
public class SchoolServiceImpl implements SchoolService {

    @Autowired
    private SchoolMapper schoolMapper;

    @Autowired
    private CollegeMapper collegeMapper;


    @Override
    public R findSchoolList() {
        List<TbSchool> tbSchools = schoolMapper.selectList(null);

        return R.success("",tbSchools);
    }

    @Override
    public R findSchoolById(Integer id) {
        TbSchool tbSchool = schoolMapper.selectOne(new QueryWrapper<TbSchool>().lambda().eq(TbSchool::getId, id));

        return R.success("",tbSchool);
    }

    @Override
    public R findCollegeBySid(Integer cid) {

        TbCollege tbCollege = collegeMapper.selectOne(new QueryWrapper<TbCollege>().lambda().eq(TbCollege::getId, cid));

        return R.success("",tbCollege);
    }

    @Override
    public R findCollegeList(Integer sid) {
        List<TbCollege> tbColleges = collegeMapper.selectList(new QueryWrapper<TbCollege>().lambda().eq(TbCollege::getSchoolId, sid));

        return R.success("",tbColleges);
    }
}